package com.butterfly.hotkey.client.core.config;

import com.butterfly.hotkey.core.model.AppCacheModel;
import com.butterfly.hotkey.core.rule.ClientKeyRule;
import com.butterfly.hotkey.core.util.KeyRuleUtil;

import java.util.List;

/**
 * @author butterfly
 * @since 2024/10/19
 */
public class AppClientProperties {

    /**
     * 应用名
     */
    private String appName;

    /**
     * 推送key的间隔(毫秒)
     * 默认0.5s
     * 推送越快，探测的越密集，会越快探测出来
     * 但对client资源消耗相应增大！
     */
    private Long pushKeyIntervalMillis = 500L;

    /**
     * 推送key 数量 的间隔(毫秒) 默认10s
     * 仅仅用于dashboard统计数据
     */
    private Long pushSummarySecs = 10L;

    /**
     * 重连worker的间隔(毫秒)
     */
    private Long reConnectWorkerIntervalMillis = 3000L;

    /**
     * 拉取客户端配置间隔(秒)
     */
    private Long fetchClientConfigSecs = 30L;

    /**
     * 拉取worker地址间隔(秒)
     */
    private Long fetchWorkerPathSecs = 30L;

    /**
     * 热key即将过期时，也推送worker
     * 单位（秒）
     */
    private int warmSecs = 2;

    /**
     * 缓存配置
     */
    private AppCacheModel cache;

    /**
     * 配置的rule
     */
    private List<ClientKeyRule> clientKeyRules;

    /**
     * 需要链接的worker地址
     */
    private List<String> workerUrls;

    /**
     * 查询key关联的规则信息
     *
     * @param key key
     * @return KeyRule
     */
    public ClientKeyRule findKeyRule(String key) {
        List<ClientKeyRule> clientKeyRules = getClientKeyRules();
        return KeyRuleUtil.findKeyRule(key, clientKeyRules);
    }

    public List<String> getWorkerUrls() {
        return workerUrls;
    }

    public void setWorkerUrls(List<String> workerUrls) {
        this.workerUrls = workerUrls;
    }

    public List<ClientKeyRule> getClientKeyRules() {
        return clientKeyRules;
    }

    public void setClientKeyRules(List<ClientKeyRule> clientKeyRules) {
        this.clientKeyRules = clientKeyRules;
    }

    public String getAppName() {
        return appName;
    }

    public void setAppName(String appName) {
        this.appName = appName;
    }

    public Long getPushKeyIntervalMillis() {
        return pushKeyIntervalMillis;
    }

    public void setPushKeyIntervalMillis(Long pushKeyIntervalMillis) {
        this.pushKeyIntervalMillis = pushKeyIntervalMillis;
    }

    public Long getPushSummarySecs() {
        return pushSummarySecs;
    }

    public void setPushSummarySecs(Long pushSummarySecs) {
        this.pushSummarySecs = pushSummarySecs;
    }

    public int getWarmSecs() {
        return warmSecs;
    }

    public void setWarmSecs(int warmSecs) {
        this.warmSecs = warmSecs;
    }

    public AppCacheModel getCache() {
        return cache;
    }

    public void setCache(AppCacheModel cache) {
        this.cache = cache;
    }

    public Long getReConnectWorkerIntervalMillis() {
        return reConnectWorkerIntervalMillis;
    }

    public void setReConnectWorkerIntervalMillis(Long reConnectWorkerIntervalMillis) {
        this.reConnectWorkerIntervalMillis = reConnectWorkerIntervalMillis;
    }

    public Long getFetchClientConfigSecs() {
        return fetchClientConfigSecs;
    }

    public void setFetchClientConfigSecs(Long fetchClientConfigSecs) {
        this.fetchClientConfigSecs = fetchClientConfigSecs;
    }

    public Long getFetchWorkerPathSecs() {
        return fetchWorkerPathSecs;
    }

    public void setFetchWorkerPathSecs(Long fetchWorkerPathSecs) {
        this.fetchWorkerPathSecs = fetchWorkerPathSecs;
    }
}
